/**
 * MIT License
 * 
 * Copyright (c) 2024 - present @ ebraid
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef __EB_SIMPLE_BUS_H__
#define __EB_SIMPLE_BUS_H__

#include <list.h>
#include <types.h>

/**
 * For some devices, we do not need a complete device bus model because it consumes memory. 
 * Therefore, a simple bus is introduced, which can only match drivers and devices without kernel objects. 
 * Therefore, when registering a simple bus, files will not be generated in the file system
 */


/**
 * @brief Simple bus device structure
 */
struct simple_driver;


/**
 * @brief Simple bus device structure
 * @entry:  list node
 * @compatible:  device compatible
 * @driver:  driver
 * @irq_num:  irq number
 */
struct simple_device {
    list_node_t  entry;
    const char  *compatible;
    struct simple_driver *driver;
    uint32_t   irq_num;
};


/**
 * @brief Simple bus driver structure
 * @entry:  list node
 * @probe:  probe function
 * @remove:  remove function
 * @of_match_table:  id table
 */
struct simple_driver {
    list_node_t  entry;
    int (*probe)(struct simple_device *dev);
    void (*remove)(struct simple_device *dev);
    struct of_device_id  *of_match_table;
};


#ifdef __cplusplus
extern "C" {
#endif


#define  SIMPLE_SYSLOG_INFO(...)   SYSLOG_INFO("simple: "##__VA_ARGS__)
#define  SIMPLE_SYSLOG_ERROR(...)  SYSLOG_ERROR("simple: "##__VA_ARGS__)
#define  SIMPLE_SYSLOG_WARN(...)   SYSLOG_WARN("simple: "##__VA_ARGS__)


/**
 * @brief simple bus register device
 * @param dev simple device
 * @return int 0: success, -1: fail
 */
int simple_device_register(struct simple_device *dev);


/**
 * @brief simple bus unregister device
 * @param dev simple device
 * @return none
 */
void simple_device_unregister(struct simple_device *dev);


/**
 * @brief simple bus register driver
 * @param drv simple driver
 * @return int 0: success, -1: fail
 */
int simple_driver_register(struct simple_driver *drv);


/**
 * @brief simple bus unregister driver
 * @param drv simple driver
 * @return none
 */
void simple_driver_unregister(struct simple_driver *drv);


#ifdef __cplusplus
}
#endif


#endif //!__EB_SIMPLE_BUS_H__